grammar emigre;

options {
    language=CSharp2;
}

tokens {
	VERSION = 'VERSION' ;
	CREATETABLE = 'CREATE TABLE' ;
	MINUS	= '-' ;
	MULT	= '*' ;
	DIV	= '/' ;
}

//@members {
//    public static void Main(string[] args) {
//        SimpleCalcLexer lex = new SimpleCalcLexer(new ANTLRFileStream(args[0]));
//       	CommonTokenStream tokens = new CommonTokenStream(lex);

//        SimpleCalcParser parser = new SimpleCalcParser(tokens);

//        try {
//            parser.expr();
//        } catch (RecognitionException e)  {
//            Console.Error.WriteLine(e.StackTrace);
//        }
//    }
//}

/*------------------------------------------------------------------
 * PARSER RULES
 *------------------------------------------------------------------*/

script 	
	: 	version statements
	;

version 
	:	'VERSION' NUMBER
	;

statements
	:	createTable | alterTable | dropTable
	;
	
createTable
	: 	CREATETABLE IDENTIFIER ('WITH PRIMARY KEY' IDENTIFIER)? ('WITH COLUMN' IDENTIFIER 'OF TYPE' IDENTIFIER ('HAVING SIZE' NUMBER)?)* 
	;

alterTable 
	:    	'ALTER TABLE' IDENTIFIER
	;
	
dropTable 
	:    	'DROP TABLE' IDENTIFIER
	;


/*------------------------------------------------------------------
 * LEXER RULES
 *------------------------------------------------------------------*/
 
IDENTIFIER : (LETTER|'_') (LETTER|NUMBER|'_')* ;

fragment LETTER :	'A' .. 'Z';

NUMBER	: (DIGIT)+ ;

WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ 	{ $channel = HIDDEN; } ;

fragment DIGIT	: '0'..'9' ;
